//
//  UIBarButtonItem+GYExtension.m
//  GoodLuck
//
//  Created by apple on 2018/1/26.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "UIBarButtonItem+GYExtension.h"

@implementation UIBarButtonItem (GYExtension)

+ (instancetype)itemWithImage:(NSString *)imageName tagret:(id)target action:(SEL)action button:(void (^)(UIButton *))btuBlock{
    	
    UIButton *btu = [[UIButton alloc] init];
    [btu setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [btu addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    btu.frame = CGRectMake(0, 0, 22, 22);
    if (btuBlock != nil) {
        btuBlock(btu);
    }
    //适配IOS11导航栏图标  IOS11之后导航栏的左右侧按钮 当图片的显示范围小于按钮frame时显示正常, 单是如果大于 则按照图片正常大小显示  两种解决办法 \
    第一种: 重新按照尺寸切图  按照尺寸来显示   \
    第二种: 在外面在包一层父视图  比如View  \
    这个情况针对于是  导航栏图标使用 initWithCustomView 来创建的按键
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 22, 22)];
    bgView.backgroundColor = [UIColor clearColor];
    [bgView addSubview:btu];
    
    return [[self alloc] initWithCustomView:bgView];
}


@end
